/*
 * TreePanel.java
 * 
 * Created on November 5, 2009, 4:09 AM
 * Renamed on Feb 3, 2010, 2:10:51 AM
 * 
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package portfolio.dbHost;
import java.awt.Component;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import portfolio.mainScreen;
/**
 *
 * @author  ACA
 */
public abstract class TreePanel extends JPanel implements MouseListener {
    protected mainScreen mainFrame  = null;
    protected Object     treeObject = null;
    
    protected JTree visibleTree     = null;
    
    /**
     *
     * @param e 
     */
    public void mouseClicked  (MouseEvent e) {}
    public void mousePressed  (MouseEvent e) {}
    public void mouseReleased (MouseEvent e) {
        Component cmpTemp = e.getComponent();
        if (cmpTemp == null)
            return; //report error

        int iXPos     = e.getX();
        int iYPos     = e.getY();
        JTree tmpTree = (JTree) cmpTemp;
        int iRow      = tmpTree.getRowForLocation (iXPos, iYPos);
        
        if (iRow == -1)
            return; //report error
        
        if (!e.isPopupTrigger())
            return;

        TreePath selPath = tmpTree.getPathForLocation (iXPos, iYPos);

        Object [] oTmpPath = selPath.getPath();
        int iTmpPathLen = oTmpPath.length;
        if (iTmpPathLen <= 0) {
            return; // report error
        }
        Object oPopup = this.getTreeObject (oTmpPath);
        if (oPopup == null) {
            return; // report error
        }
//            String sClassName = oPopup.getClass().getName();

        this.getClassPopupOption (oPopup, iXPos, iYPos);
    }
    public void mouseEntered  (MouseEvent e) {}
    public void mouseExited   (MouseEvent e) {} 
    
    /** Creates new form BeanForm */
    public TreePanel () 
    {
        initComponents();
    }
    /**
     * 
     */
    private void initComponents() {
    }// </editor-fold>                        
  /**
   * 
   */
  abstract Object getTreeObject (Object [] objectPath);
  /**
   *
   */
   public JTree getTree () {return visibleTree;}
   /**
    * 
    */
   abstract mainScreen getMainScreen (Object treeObject);
   /**
    * 
    */
   abstract DefaultMutableTreeNode getMutableTreeNode (Object treeObject);
   /**
    * 
    */
   abstract void getClassPopupOption (Object oPopup, int iXPos, int iYPos);
}
